package com.ruoyi.controller.fanruan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.jpjs.common.fanruan.HbFirst;
import com.ruoyi.service.fanruan.IHbFirstService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 环保集团Controller
 *
 * @author ruoyi
 * @date 2020-11-04
 */
@Controller
@RequestMapping("/fanruan/hb")
public class HbFirstController extends BaseController
{
    private String prefix = "fanruan/hb";

    @Autowired
    private IHbFirstService hbFirstService;

    @RequiresPermissions("fanruan:hb:view")
    @GetMapping()
    public String hb()
    {
        return "fanruan/hb/hb";
    }

    /**
     * 查询环保集团列表
     */
    @RequiresPermissions("fanruan:hb:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HbFirst hbFirst)
    {
        startPage();
        List<HbFirst> list = hbFirstService.selectHbFirstList(hbFirst);
        return getDataTable(list);
    }

    /**
     * 导出环保集团列表
     */
    @RequiresPermissions("fanruan:hb:export")
    @Log(title = "环保集团", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HbFirst hbFirst)
    {
        List<HbFirst> list = hbFirstService.selectHbFirstList(hbFirst);
        ExcelUtil<HbFirst> util = new ExcelUtil<HbFirst>(HbFirst.class);
        return util.exportExcel(list, "hb");
    }

    /**
     * 新增环保集团
     */
    @GetMapping("/add")
    public String add()
    {
        return "fanruan/hb/add";
    }

    /**
     * 新增保存环保集团
     */
    @RequiresPermissions("fanruan:hb:add")
    @Log(title = "环保集团", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HbFirst hbFirst)
    {
        return toAjax(hbFirstService.insertHbFirst(hbFirst));
    }

    /**
     * 修改环保集团
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HbFirst hbFirst = hbFirstService.selectHbFirstById(id);
        mmap.put("hbFirst", hbFirst);
        return "fanruan/hb/edit";
    }

    /**
     * 修改保存环保集团
     */
    @RequiresPermissions("fanruan:hb:edit")
    @Log(title = "环保集团", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HbFirst hbFirst)
    {
        return toAjax(hbFirstService.updateHbFirst(hbFirst));
    }

    /**
     * 删除环保集团
     */
    @RequiresPermissions("fanruan:hb:remove")
    @Log(title = "环保集团", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hbFirstService.deleteHbFirstByIds(ids));
    }
}
